import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;

/**
 * 栈接口
 */
interface SStack<T> {

    boolean isEmpty();

    void push(T x);

    T pop();

    T get();
}
class SeqStack<T> implements SStack<T> {

    private Object element[];
    private int top;


    public SeqStack(int size) {
        this.element = new Object[Math.abs(size)];
        this.top = -1;
    }


    public SeqStack() {
        this(64);
    }

    @Override

    public boolean isEmpty() {
        return this.top == -1;
    }

    @Override

    public void push(T x) {
        if (x == null) {
            return;
        }
        if (this.top == element.length - 1) {
            Object[] temp = this.element;
            this.element = new Object[temp.length * 2];
            // 复制数组元素
            for (int i = 0; i < temp.length; i++)
                this.element[i] = temp[i];
        }
        this.top++;
        this.element[this.top] = x;
    }

    @SuppressWarnings("unchecked")
    @Override

    public T pop() {
        return this.top == -1 ? null : (T) element[top--];
    }

    @SuppressWarnings("unchecked")
    @Override

    public T get() {
        return this.top == -1 ? null : (T) element[top];
    }
}

public class YY {
    public static void main(String[] args) throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        String s;
        s = scanner.readLine();
        StringBuilder res = new StringBuilder();
        SeqStack<String> stack = new SeqStack<>();
        while (!s.trim().equals("E")){
            String[] temp = s.split(" ");
            StringBuilder tempStr = new StringBuilder();
            if(Objects.equals(temp[0], "A")){
                for(int i = 1;i< temp.length;i++){
                    if(i == temp.length - 1){
                        tempStr.append(temp[i]);
                    }else {
                        tempStr.append(temp[i]).append(" ");
                    }
                }
                stack.push(String.valueOf(tempStr));
            }else if (Objects.equals(temp[0], "B")){
                res.append(stack.pop()).append(" ").append('\n');
            }
            s = scanner.readLine();
        }
        System.out.print(res.substring(0,res.length()-1)+" ");
    }
}
